package com.zhongyu.controller;

import com.zhongyu.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 控制层全局异常处理器
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    public ResultVo handleException(RuntimeException ex){
        if(ex instanceof UnauthorizedException){
            log.error("该用户没有授权！",ex);
        }else{
            log.error("全局异常处理器捕获到异常！", ex);
        }
        return   ResultVo.failure("用户操作失败!");
    }



}
